from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class ThreeDaysVolumeIncreaseStrategy(BaseStrategy):
    """
    连续3天成交量放大策略，成交量逐日增加
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析过去3天的成交量是否连续放大
        """
        node_point = 0
        description = ""

        # 确保至少有3天的交易数据
        if len(trade_info_list) >= 3:
            # 检查过去3天的成交量是否连续放大
            for i in range(2, len(trade_info_list)):
                # 检查当前天成交量是否大于前一天的成交量
                if trade_info_list[i].vol > trade_info_list[i - 1].vol:
                    node_point += 1  # 每天成交量放大得分 +1
                    description += f"第{i}天：与前一天相比，交易量增加. "

                    # 如果当天成交量比前两天放大幅度较大，得分 +2
                    if trade_info_list[i].vol > trade_info_list[i - 1].vol * 1.5:
                        node_point += 2
                        description += f"Day {i}: Volume increased by more than 50% compared to the previous day. "

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            confif=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> dict:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="three_days_volume_increase",
            strategy_name="成交量连续放大",
            strategy_group=StrategyGroup.ATTENTION,
            strategy_type=StrategyType.VOLUME,
            analysis_day=3,
            strategy_level=2,
        )
